.class public Lcom/example/security/library/Net;
.super Ljava/lang/Object;
.source "Net.java"


# static fields
.field protected static final baseUrl:Ljava/lang/String; = "http://storm-project.fr/secu"


# direct methods
.method public constructor <init>()V
    .locals 0

    .prologue
    .line 27
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    return-void
.end method

.method protected static varargs add(Ljava/util/List;[Ljava/lang/Object;)V
    .locals 4
    .parameter
    .parameter "donnes"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/util/List",
            "<",
            "Lorg/apache/http/NameValuePair;",
            ">;[",
            "Ljava/lang/Object;",
            ")V"
        }
    .end annotation

    .prologue
    .line 42
    .local p0, donneesPost:Ljava/util/List;,"Ljava/util/List<Lorg/apache/http/NameValuePair;>;"
    const/4 v1, 0x0

    .local v1, i:I
    :goto_0
    array-length v3, p1

    if-lt v1, v3, :cond_0

    .line 47
    return-void

    .line 43
    :cond_0
    aget-object v3, p1, v1

    invoke-virtual {v3}, Ljava/lang/Object;->toString()Ljava/lang/String;

    move-result-object v0

    .line 44
    .local v0, cle:Ljava/lang/String;
    add-int/lit8 v3, v1, 0x1

    aget-object v3, p1, v3

    invoke-virtual {v3}, Ljava/lang/Object;->toString()Ljava/lang/String;

    move-result-object v2

    .line 45
    .local v2, valeur:Ljava/lang/String;
    new-instance v3, Lorg/apache/http/message/BasicNameValuePair;

    invoke-direct {v3, v0, v2}, Lorg/apache/http/message/BasicNameValuePair;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    invoke-interface {p0, v3}, Ljava/util/List;->add(Ljava/lang/Object;)Z

    .line 42
    add-int/lit8 v1, v1, 0x2

    goto :goto_0
.end method

.method public static connect(Ljava/lang/String;Ljava/lang/String;)[Lcom/example/security/library/Action;
    .locals 4
    .parameter "id"
    .parameter "name"

    .prologue
    .line 86
    const-string v0, "/device/connected"

    const/4 v1, 0x4

    new-array v1, v1, [Ljava/lang/Object;

    const/4 v2, 0x0

    .line 88
    const-string v3, "id"

    aput-object v3, v1, v2

    const/4 v2, 0x1

    aput-object p0, v1, v2

    const/4 v2, 0x2

    .line 89
    const-string v3, "name"

    aput-object v3, v1, v2

    const/4 v2, 0x3

    aput-object p1, v1, v2

    .line 87
    invoke-static {v1}, Lcom/example/security/library/Net;->construireDonnes([Ljava/lang/Object;)Ljava/util/List;

    move-result-object v1

    .line 86
    invoke-static {v0, v1}, Lcom/example/security/library/Net;->requete(Ljava/lang/String;Ljava/util/List;)Ljava/lang/String;

    move-result-object v0

    .line 85
    invoke-static {v0}, Lcom/example/security/library/Net;->parserAction(Ljava/lang/String;)[Lcom/example/security/library/Action;

    move-result-object v0

    return-object v0
.end method

.method protected static varargs construireDonnes([Ljava/lang/Object;)Ljava/util/List;
    .locals 1
    .parameter "donnes"
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "([",
            "Ljava/lang/Object;",
            ")",
            "Ljava/util/List",
            "<",
            "Lorg/apache/http/NameValuePair;",
            ">;"
        }
    .end annotation

    .prologue
    .line 36
    new-instance v0, Ljava/util/ArrayList;

    invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V

    .line 37
    .local v0, donneesPost:Ljava/util/List;,"Ljava/util/List<Lorg/apache/http/NameValuePair;>;"
    invoke-static {v0, p0}, Lcom/example/security/library/Net;->add(Ljava/util/List;[Ljava/lang/Object;)V

    .line 38
    return-object v0
.end method

.method public static executed(Ljava/lang/String;Ljava/lang/String;)V
    .locals 4
    .parameter "deviceId"
    .parameter "actionId"

    .prologue
    .line 95
    const-string v0, "/device/executed"

    const/4 v1, 0x4

    new-array v1, v1, [Ljava/lang/Object;

    const/4 v2, 0x0

    .line 97
    const-string v3, "id"

    aput-object v3, v1, v2

    const/4 v2, 0x1

    aput-object p0, v1, v2

    const/4 v2, 0x2

    .line 98
    const-string v3, "action"

    aput-object v3, v1, v2

    const/4 v2, 0x3

    aput-object p1, v1, v2

    .line 96
    invoke-static {v1}, Lcom/example/security/library/Net;->construireDonnes([Ljava/lang/Object;)Ljava/util/List;

    move-result-object v1

    .line 95
    invoke-static {v0, v1}, Lcom/example/security/library/Net;->requete(Ljava/lang/String;Ljava/util/List;)Ljava/lang/String;

    .line 100
    return-void
.end method

.method protected static newListNameValuePair()Ljava/util/List;
    .locals 1
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "()",
            "Ljava/util/List",
            "<",
            "Lorg/apache/http/NameValuePair;",
            ">;"
        }
    .end annotation

    .prologue
    .line 32
    new-instance v0, Ljava/util/ArrayList;

    invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V

    return-object v0
.end method

.method public static parserAction(Ljava/lang/String;)[Lcom/example/security/library/Action;
    .locals 12
    .parameter "texte"

    .prologue
    .line 103
    const/4 v0, 0x0

    .line 106
    .local v0, actions:[Lcom/example/security/library/Action;
    :try_start_0
    new-instance v4, Lorg/json/JSONObject;

    invoke-direct {v4, p0}, Lorg/json/JSONObject;-><init>(Ljava/lang/String;)V

    .line 108
    .local v4, json:Lorg/json/JSONObject;
    const-string v10, "actions"

    invoke-virtual {v4, v10}, Lorg/json/JSONObject;->getJSONArray(Ljava/lang/String;)Lorg/json/JSONArray;

    move-result-object v6

    .line 109
    .local v6, jsonActions:Lorg/json/JSONArray;
    invoke-virtual {v6}, Lorg/json/JSONArray;->length()I

    move-result v10

    new-array v0, v10, [Lcom/example/security/library/Action;

    .line 111
    const/4 v2, 0x0

    .local v2, i:I
    :goto_0
    invoke-virtual {v6}, Lorg/json/JSONArray;->length()I

    move-result v10

    if-lt v2, v10, :cond_0

    .line 133
    .end local v2           #i:I
    .end local v4           #json:Lorg/json/JSONObject;
    .end local v6           #jsonActions:Lorg/json/JSONArray;
    :goto_1
    return-object v0

    .line 112
    .restart local v2       #i:I
    .restart local v4       #json:Lorg/json/JSONObject;
    .restart local v6       #jsonActions:Lorg/json/JSONArray;
    :cond_0
    invoke-virtual {v6, v2}, Lorg/json/JSONArray;->getJSONObject(I)Lorg/json/JSONObject;

    move-result-object v5

    .line 114
    .local v5, jsonAction:Lorg/json/JSONObject;
    new-instance v10, Lcom/example/security/library/Action;

    invoke-direct {v10}, Lcom/example/security/library/Action;-><init>()V

    aput-object v10, v0, v2

    .line 116
    aget-object v10, v0, v2

    const-string v11, "id"

    invoke-virtual {v5, v11}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v11

    iput-object v11, v10, Lcom/example/security/library/Action;->id:Ljava/lang/String;

    .line 117
    aget-object v10, v0, v2

    const-string v11, "type"

    invoke-virtual {v5, v11}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v11

    iput-object v11, v10, Lcom/example/security/library/Action;->type:Ljava/lang/String;

    .line 119
    const-string v10, "params"

    invoke-virtual {v5, v10}, Lorg/json/JSONObject;->getJSONObject(Ljava/lang/String;)Lorg/json/JSONObject;

    move-result-object v7

    .line 120
    .local v7, jsonParams:Lorg/json/JSONObject;
    invoke-virtual {v7}, Lorg/json/JSONObject;->keys()Ljava/util/Iterator;

    move-result-object v3

    .line 121
    .local v3, iter:Ljava/util/Iterator;
    :goto_2
    invoke-interface {v3}, Ljava/util/Iterator;->hasNext()Z

    move-result v10

    if-nez v10, :cond_1

    .line 111
    add-int/lit8 v2, v2, 0x1

    goto :goto_0

    .line 122
    :cond_1
    invoke-interface {v3}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v8

    check-cast v8, Ljava/lang/String;

    .line 123
    .local v8, key:Ljava/lang/String;
    invoke-virtual {v7, v8}, Lorg/json/JSONObject;->getString(Ljava/lang/String;)Ljava/lang/String;

    move-result-object v9

    .line 124
    .local v9, value:Ljava/lang/String;
    aget-object v10, v0, v2

    iget-object v10, v10, Lcom/example/security/library/Action;->params:Ljava/util/Map;

    invoke-interface {v10, v8, v9}, Ljava/util/Map;->put(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;
    :try_end_0
    .catch Lorg/json/JSONException; {:try_start_0 .. :try_end_0} :catch_0

    goto :goto_2

    .line 129
    .end local v2           #i:I
    .end local v3           #iter:Ljava/util/Iterator;
    .end local v4           #json:Lorg/json/JSONObject;
    .end local v5           #jsonAction:Lorg/json/JSONObject;
    .end local v6           #jsonActions:Lorg/json/JSONArray;
    .end local v7           #jsonParams:Lorg/json/JSONObject;
    .end local v8           #key:Ljava/lang/String;
    .end local v9           #value:Ljava/lang/String;
    :catch_0
    move-exception v1

    .line 130
    .local v1, e:Lorg/json/JSONException;
    invoke-virtual {v1}, Lorg/json/JSONException;->printStackTrace()V

    goto :goto_1
.end method

.method protected static requete(Ljava/lang/String;Ljava/util/List;)Ljava/lang/String;
    .locals 9
    .parameter "url"
    .parameter
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "(",
            "Ljava/lang/String;",
            "Ljava/util/List",
            "<",
            "Lorg/apache/http/NameValuePair;",
            ">;)",
            "Ljava/lang/String;"
        }
    .end annotation

    .prologue
    .line 52
    .local p1, donneesPost:Ljava/util/List;,"Ljava/util/List<Lorg/apache/http/NameValuePair;>;"
    new-instance v1, Lorg/apache/http/impl/client/DefaultHttpClient;

    invoke-direct {v1}, Lorg/apache/http/impl/client/DefaultHttpClient;-><init>()V

    .line 55
    .local v1, httpClient:Lorg/apache/http/client/HttpClient;
    :try_start_0
    new-instance v6, Ljava/lang/StringBuilder;

    const-string v7, "http://storm-project.fr/secu"

    invoke-direct {v6, v7}, Ljava/lang/StringBuilder;-><init>(Ljava/lang/String;)V

    invoke-virtual {v6, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    const-string v7, ".php"

    invoke-virtual {v6, v7}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    .line 57
    .local v5, urlPost:Ljava/lang/String;
    new-instance v3, Lorg/apache/http/client/methods/HttpPost;

    invoke-direct {v3, v5}, Lorg/apache/http/client/methods/HttpPost;-><init>(Ljava/lang/String;)V

    .line 59
    .local v3, requete:Lorg/apache/http/client/methods/HttpPost;
    if-eqz p1, :cond_0

    .line 60
    new-instance v6, Lorg/apache/http/client/entity/UrlEncodedFormEntity;

    const-string v7, "UTF-8"

    invoke-direct {v6, p1, v7}, Lorg/apache/http/client/entity/UrlEncodedFormEntity;-><init>(Ljava/util/List;Ljava/lang/String;)V

    invoke-virtual {v3, v6}, Lorg/apache/http/client/methods/HttpPost;->setEntity(Lorg/apache/http/HttpEntity;)V

    .line 62
    :cond_0
    const-string v6, "NET"

    invoke-static {v6, v5}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I

    .line 63
    invoke-interface {v1, v3}, Lorg/apache/http/client/HttpClient;->execute(Lorg/apache/http/client/methods/HttpUriRequest;)Lorg/apache/http/HttpResponse;

    move-result-object v2

    .line 65
    .local v2, httpReponse:Lorg/apache/http/HttpResponse;
    invoke-interface {v2}, Lorg/apache/http/HttpResponse;->getEntity()Lorg/apache/http/HttpEntity;

    move-result-object v6

    const-string v7, "ISO-8859-1"

    invoke-static {v6, v7}, Lorg/apache/http/util/EntityUtils;->toString(Lorg/apache/http/HttpEntity;Ljava/lang/String;)Ljava/lang/String;

    move-result-object v6

    invoke-virtual {v6}, Ljava/lang/String;->trim()Ljava/lang/String;

    move-result-object v6

    const-string v7, "&aecute"

    const-string v8, "\u00d4\u00f8\u03a9"

    invoke-virtual {v6, v7, v8}, Ljava/lang/String;->replace(Ljava/lang/CharSequence;Ljava/lang/CharSequence;)Ljava/lang/String;

    move-result-object v4

    .line 66
    .local v4, response:Ljava/lang/String;
    const-string v6, "NET"

    invoke-static {v6, v4}, Landroid/util/Log;->d(Ljava/lang/String;Ljava/lang/String;)I
    :try_end_0
    .catchall {:try_start_0 .. :try_end_0} :catchall_0
    .catch Lorg/apache/http/client/ClientProtocolException; {:try_start_0 .. :try_end_0} :catch_0
    .catch Ljava/io/IOException; {:try_start_0 .. :try_end_0} :catch_1

    .line 76
    if-eqz v1, :cond_1

    .line 77
    invoke-interface {v1}, Lorg/apache/http/client/HttpClient;->getConnectionManager()Lorg/apache/http/conn/ClientConnectionManager;

    move-result-object v6

    invoke-interface {v6}, Lorg/apache/http/conn/ClientConnectionManager;->shutdown()V

    .line 81
    .end local v2           #httpReponse:Lorg/apache/http/HttpResponse;
    .end local v3           #requete:Lorg/apache/http/client/methods/HttpPost;
    .end local v4           #response:Ljava/lang/String;
    .end local v5           #urlPost:Ljava/lang/String;
    :cond_1
    :goto_0
    return-object v4

    .line 70
    :catch_0
    move-exception v0

    .line 71
    .local v0, e:Lorg/apache/http/client/ClientProtocolException;
    :try_start_1
    invoke-virtual {v0}, Lorg/apache/http/client/ClientProtocolException;->printStackTrace()V
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catchall_0

    .line 76
    if-eqz v1, :cond_2

    .line 77
    invoke-interface {v1}, Lorg/apache/http/client/HttpClient;->getConnectionManager()Lorg/apache/http/conn/ClientConnectionManager;

    move-result-object v6

    invoke-interface {v6}, Lorg/apache/http/conn/ClientConnectionManager;->shutdown()V

    .line 80
    .end local v0           #e:Lorg/apache/http/client/ClientProtocolException;
    :cond_2
    :goto_1
    const-string v6, "NET"

    const-string v7, "echec de la requete"

    invoke-static {v6, v7}, Landroid/util/Log;->e(Ljava/lang/String;Ljava/lang/String;)I

    .line 81
    const/4 v4, 0x0

    goto :goto_0

    .line 72
    :catch_1
    move-exception v0

    .line 73
    .local v0, e:Ljava/io/IOException;
    :try_start_2
    invoke-virtual {v0}, Ljava/io/IOException;->printStackTrace()V
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catchall_0

    .line 76
    if-eqz v1, :cond_2

    .line 77
    invoke-interface {v1}, Lorg/apache/http/client/HttpClient;->getConnectionManager()Lorg/apache/http/conn/ClientConnectionManager;

    move-result-object v6

    invoke-interface {v6}, Lorg/apache/http/conn/ClientConnectionManager;->shutdown()V

    goto :goto_1

    .line 75
    .end local v0           #e:Ljava/io/IOException;
    :catchall_0
    move-exception v6

    .line 76
    if-eqz v1, :cond_3

    .line 77
    invoke-interface {v1}, Lorg/apache/http/client/HttpClient;->getConnectionManager()Lorg/apache/http/conn/ClientConnectionManager;

    move-result-object v7

    invoke-interface {v7}, Lorg/apache/http/conn/ClientConnectionManager;->shutdown()V

    .line 78
    :cond_3
    throw v6
.end method
